<?php

/* Devil Web Framework project
 *
 * This file is part of Devil Web Framework project.
 * All project is under the GPL3.0 license.
 * For any suggestion email at dan.andreoli@gmail.com
 */

/**
 * @author Daniele Andreoli <dan.andreoli@gmail.com>
 */
namespace core;

class Autoloader
{
    static public function register()
    {
        define("PROG_ROOT", dirname(__FILE__)."/..");

        spl_autoload_register(null, false);
        spl_autoload_register(array("\\core\\Autoloader", "autoload"));
    }

    static public function autoload($class)
    {
        if (substr($class, 0, 1) != "\\") {
            $class = "\\".$class;
        }

        $file = PROG_ROOT.str_replace("\\", "/", $class).".php";

        if (file_exists($file)) {
            require $file;
        }
        else {
            throw new \Exception("Class '".$class."' could not be loaded");
        }
    }
}

?>
